define([ "Zepto", "underscore", "Backbone", "Handlebars",
         "views/course/scheduleitemview"
         ], function($, _, Backbone, Handlebars, ScheduleItemView, template) {

	var SchedulesView = Backbone.View.extend({

		template : Handlebars.compile(template),

		initialize : function() {
			this.model.bind("reset", this.render, this);
		},

		render : function(eventName) {
			 // alert(this.model.models);
			 $(this.el).empty();

			  _.each(this.model.models,
					function(element) {
						﻿$(this.el).append(new ScheduleItemView({
							tagName : 'a', //Crea un nuovo tag <a> invece di usarne uno già presente nel DOM
							attributes : {
								'href' : '#hall/'+element.get('aula').objectId
							},
							﻿model : element
						}).render().el);
					 },
					 this);

			 var schedulescroll = new iScroll('schedule',
                                  { useTransition:false,
                                    checkDOMChanges: true,
                                    hideScrollbar: true,
                                    fixedScrollbar:true });
		}

	});
	

	return SchedulesView;
});
